package com.ourteam.workspace.dao.impl;

import com.ourteam.workspace.dao.IWorkspaceFileTypeConfigDAO;
import com.ourteam.workspace.dao.WorkspaceFileTypeConfig;
import com.ourteam.workspace.dao.WorkspaceFileTypeConfigDAOQueryBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;
import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.jdbc.core.RowMapper;

/**
 * Template Name : DAO服务对象 Template Version : 1 Template Last Modfiy Date : Fri Nov 17 11:00:11 CST
 * 2017 Auto Generate Date : 2018-11-30 18:42:34 Warning ! This file will be overwrite when
 * regenerate !
 */
public class AbstractWorkspaceFileTypeConfigDAOJdbcImpl extends AbstractSpringDAO
    implements IWorkspaceFileTypeConfigDAO {

  public static final String[] ENTITY_FIELDS =
      new String[] {
        Id,
        FileTypeName,
        FileExtension,
        FileEditorMode,
        FileTypeIcon,
        IsCountLine,
        IsCanDiff,
        Status,
        Remarks
      };

  public static final String[] ENTITY_PROPERTIES =
      new String[] {
        _DataObjectProperty.Id,
        _DataObjectProperty.FileTypeName,
        _DataObjectProperty.FileExtension,
        _DataObjectProperty.FileEditorMode,
        _DataObjectProperty.FileTypeIcon,
        _DataObjectProperty.IsCountLine,
        _DataObjectProperty.IsCanDiff,
        _DataObjectProperty.Status,
        _DataObjectProperty.Remarks
      };

  public static final String[] ENTITY_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};

  private static String relatedJoinSQL = null;

  private static String basicFilterSQL = null;

  private DataAccessObjectHelper<WorkspaceFileTypeConfig, WorkspaceFileTypeConfigDAOQueryBean>
      daoHelper;

  public AbstractWorkspaceFileTypeConfigDAOJdbcImpl() {
    super();
    daoHelper =
        new DataAccessObjectHelper<WorkspaceFileTypeConfig, WorkspaceFileTypeConfigDAOQueryBean>(
            this);
  }

  protected String getEntityName() {
    return EntityName;
  }

  protected String[] getEntityFields() {
    return ENTITY_FIELDS;
  }

  protected String[] getEntityProperties() {
    return ENTITY_PROPERTIES;
  }

  protected String[] getEntityPKFields() {
    return ENTITY_PK_FIELDS;
  }

  protected String[] getEntityAutoGenPKFields() {
    return ENTITY_AUTO_GEN_PK_FIELDS;
  }

  protected String[] getEntityUniqueFields() {
    return ENTITY_UNIQUE_FIELDS;
  }

  protected String getBaiscQueryFilter() {

    if (basicFilterSQL == null) {
      StringBuffer basicFilterSQLbuffer = new StringBuffer();

      basicFilterSQL = basicFilterSQLbuffer.toString();
    }

    return basicFilterSQL;
  }

  protected String getRelatedJoinSQL() {

    if (relatedJoinSQL == null) {
      StringBuffer relatedJoinSQLBuffer = new StringBuffer();

      relatedJoinSQL = relatedJoinSQLBuffer.toString();
    }

    return relatedJoinSQL;
  }

  /**
   * Check Data Unique
   *
   * @param aWorkspaceFileTypeConfig
   * @throws Exception
   */
  public boolean checkIsUnique(WorkspaceFileTypeConfig aWorkspaceFileTypeConfig) throws Exception {

    if (aWorkspaceFileTypeConfig == null) {
      return true;
    }

    List valueList = new ArrayList();

    List pkValueList = new ArrayList();

    pkValueList.add(aWorkspaceFileTypeConfig.getId());

    return isUnique(
        valueList.toArray(new Object[valueList.size()]),
        pkValueList.toArray(new Object[pkValueList.size()]));
  }

  /**
   * Insert Data
   *
   * @param aWorkspaceFileTypeConfig
   * @throws Exception
   */
  public void insert(WorkspaceFileTypeConfig aWorkspaceFileTypeConfig) throws Exception {

    super.doInsert(aWorkspaceFileTypeConfig);
  }

  /**
   * Batch Insert Datas
   *
   * @param aWorkspaceFileTypeConfig
   * @throws Exception
   */
  public void batchInsert(WorkspaceFileTypeConfig[] aWorkspaceFileTypeConfigs) throws Exception {

    super.doBatchInsert(aWorkspaceFileTypeConfigs);
  }

  /**
   * Delete Data
   *
   * @param final long id *
   * @throws Exception
   */
  public void delete(final long id) throws Exception {

    super.doDeleteById(new Object[] {new Long(id)});
  }

  /**
   * Delete Datas
   *
   * @param queryBean
   * @throws Exception
   */
  public void delete(WorkspaceFileTypeConfigDAOQueryBean queryBean) throws Exception {

    super.doDeleteByQuery(queryBean);
  }

  public void delete(WorkspaceFileTypeConfig aWorkspaceFileTypeConfig) throws Exception {

    delete(aWorkspaceFileTypeConfig.getId());
  }

  /**
   * Update Data Selective
   *
   * @param aWorkspaceFileTypeConfig
   * @throws Exception
   */
  public void update(WorkspaceFileTypeConfig aWorkspaceFileTypeConfig) throws Exception {

    if (aWorkspaceFileTypeConfig.getId() == 0) {
      throw new Exception("Can not update object data whith out primary key value");
    }

    super.doUpdate(aWorkspaceFileTypeConfig);

    WorkspaceFileTypeConfig tempObj = findById(aWorkspaceFileTypeConfig.getId());

    if (tempObj != null) {
      PropertyUtils.copyProperties(aWorkspaceFileTypeConfig, tempObj);
    }
  }

  /**
   * Batch Update Datas
   *
   * @param aWorkspaceFileTypeConfigs[]
   * @throws Exception
   */
  public void batchUpdate(WorkspaceFileTypeConfig[] aWorkspaceFileTypeConfigs) throws Exception {

    super.doBatchUpdate(aWorkspaceFileTypeConfigs);
  }

  /**
   * Update Data By Condictions
   *
   * @param aWorkspaceFileTypeConfig
   * @param aValueCriteria
   * @param aTransaction
   * @throws Exception
   */
  public void update(
      WorkspaceFileTypeConfig aWorkspaceFileTypeConfig,
      WorkspaceFileTypeConfigDAOQueryBean aQueryBean)
      throws Exception {

    super.doUpdateByQuery(aWorkspaceFileTypeConfig, aQueryBean);
  }

  /**
   * Update Data By Condictions
   *
   * @param aQueryBean
   * @throws Exception
   */
  public void update(WorkspaceFileTypeConfigDAOQueryBean aQueryBean) throws Exception {
    super.doUpdateByQuery(aQueryBean);
  }

  protected void checkNullValue(WorkspaceFileTypeConfig aWorkspaceFileTypeConfig) throws Exception {

    if (aWorkspaceFileTypeConfig.getFileTypeName() == null) {
      throw new Exception("The WorkspaceFileTypeConfig.fileTypeName value is not allow NULL");
    }

    if (aWorkspaceFileTypeConfig.getFileExtension() == null) {
      throw new Exception("The WorkspaceFileTypeConfig.fileExtension value is not allow NULL");
    }

    if (aWorkspaceFileTypeConfig.getFileEditorMode() == null) {
      throw new Exception("The WorkspaceFileTypeConfig.fileEditorMode value is not allow NULL");
    }

    if (aWorkspaceFileTypeConfig.getFileTypeIcon() == null) {
      throw new Exception("The WorkspaceFileTypeConfig.fileTypeIcon value is not allow NULL");
    }

    if (aWorkspaceFileTypeConfig.getIsCountLine() == null) {
      throw new Exception("The WorkspaceFileTypeConfig.isCountLine value is not allow NULL");
    }

    if (aWorkspaceFileTypeConfig.getIsCanDiff() == null) {
      throw new Exception("The WorkspaceFileTypeConfig.isCanDiff value is not allow NULL");
    }

    if (aWorkspaceFileTypeConfig.getStatus() == null) {
      throw new Exception("The WorkspaceFileTypeConfig.status value is not allow NULL");
    }

    if (aWorkspaceFileTypeConfig.getRemarks() == null) {
      throw new Exception("The WorkspaceFileTypeConfig.remarks value is not allow NULL");
    }
  }

  /**
   * Get Data By ID
   *
   * @param final long id * @return ${businessObject.name}
   * @throws Exception
   */
  public WorkspaceFileTypeConfig findById(final long id) throws Exception {

    WorkspaceFileTypeConfigDAOQueryBean queryBean = new WorkspaceFileTypeConfigDAOQueryBean();

    WorkspaceFileTypeConfigDAOQueryBean.Criteria criteria = queryBean.createCriteria();

    criteria.andIdEqualTo(id);

    // queryBean.setDistinct(true);

    WorkspaceFileTypeConfig[] WorkspaceFileTypeConfigs = query(queryBean);

    if (WorkspaceFileTypeConfigs.length == 0) {
      return null;
    } else {
      return WorkspaceFileTypeConfigs[0];
    }
  }

  /**
   * Query Data
   *
   * @param queryBean
   * @return WorkspaceFileTypeConfig[]
   * @throws Exception
   */
  public WorkspaceFileTypeConfig[] query(WorkspaceFileTypeConfigDAOQueryBean queryBean)
      throws Exception {

    List result = super.doQuery(queryBean, new JdbcWorkspaceFileTypeConfigRowMapper());

    return (WorkspaceFileTypeConfig[]) result.toArray(new WorkspaceFileTypeConfig[result.size()]);
  }

  /**
   * Query ${businessObject.name} Selective
   *
   * @param queryBean
   * @return Map[]
   * @model
   * @throws Exception
   */
  public Map<String, Object>[] querySelective(WorkspaceFileTypeConfigDAOQueryBean queryBean)
      throws Exception {

    if (queryBean.getSelectProperties().isEmpty()) {
      queryBean.addAllSelectProperties();
    }

    return super.doQuerySelective(queryBean);
  }

  /**
   * Query Data Count
   *
   * @param queryBean
   * @return int
   * @throws Exception
   */
  public int queryCount(WorkspaceFileTypeConfigDAOQueryBean queryBean) throws Exception {

    return super.doQueryCount(queryBean);
  }

  public void synchronize(
      WorkspaceFileTypeConfig[] aWorkspaceFileTypeConfigs,
      WorkspaceFileTypeConfigDAOQueryBean queryBean)
      throws Exception {
    daoHelper.synchronize(aWorkspaceFileTypeConfigs, queryBean);
  }

  public void synchronize(
      WorkspaceFileTypeConfig[] aWorkspaceFileTypeConfigs,
      WorkspaceFileTypeConfigDAOQueryBean queryBean,
      net.dao.IDataAccessInterface.ISynchronizeCallback<WorkspaceFileTypeConfig> callBack)
      throws Exception {
    daoHelper.synchronize(aWorkspaceFileTypeConfigs, queryBean, callBack);
  }

  public static class JdbcWorkspaceFileTypeConfigRowMapper
      implements RowMapper<WorkspaceFileTypeConfig> {

    public WorkspaceFileTypeConfig mapRow(ResultSet resultSet, int arg1) throws SQLException {
      WorkspaceFileTypeConfig object = new WorkspaceFileTypeConfig();

      int columnIndex = 1;

      int __dataType;

      try {

        Object id = null;

        id = resultSet.getObject(columnIndex++);

        object.setIdNull(resultSet.getBoolean(columnIndex++));

        if (id != null) {

          setBeanValue(object, _DataObjectProperty.Id, id);
        }

        Object fileTypeName = null;

        fileTypeName = resultSet.getObject(columnIndex++);

        object.setFileTypeNameNull(resultSet.getBoolean(columnIndex++));

        if (fileTypeName != null) {

          setBeanValue(object, _DataObjectProperty.FileTypeName, fileTypeName);
        }

        Object fileExtension = null;

        fileExtension = resultSet.getObject(columnIndex++);

        object.setFileExtensionNull(resultSet.getBoolean(columnIndex++));

        if (fileExtension != null) {

          setBeanValue(object, _DataObjectProperty.FileExtension, fileExtension);
        }

        Object fileEditorMode = null;

        fileEditorMode = resultSet.getObject(columnIndex++);

        object.setFileEditorModeNull(resultSet.getBoolean(columnIndex++));

        if (fileEditorMode != null) {

          setBeanValue(object, _DataObjectProperty.FileEditorMode, fileEditorMode);
        }

        Object fileTypeIcon = null;

        fileTypeIcon = resultSet.getObject(columnIndex++);

        object.setFileTypeIconNull(resultSet.getBoolean(columnIndex++));

        if (fileTypeIcon != null) {

          setBeanValue(object, _DataObjectProperty.FileTypeIcon, fileTypeIcon);
        }

        Object isCountLine = null;

        isCountLine = resultSet.getObject(columnIndex++);

        object.setIsCountLineNull(resultSet.getBoolean(columnIndex++));

        if (isCountLine != null) {

          setBeanValue(object, _DataObjectProperty.IsCountLine, isCountLine);
        }

        Object isCanDiff = null;

        isCanDiff = resultSet.getObject(columnIndex++);

        object.setIsCanDiffNull(resultSet.getBoolean(columnIndex++));

        if (isCanDiff != null) {

          setBeanValue(object, _DataObjectProperty.IsCanDiff, isCanDiff);
        }

        Object status = null;

        status = resultSet.getObject(columnIndex++);

        object.setStatusNull(resultSet.getBoolean(columnIndex++));

        if (status != null) {

          setBeanValue(object, _DataObjectProperty.Status, status);
        }

        Object remarks = null;

        remarks = resultSet.getObject(columnIndex++);

        object.setRemarksNull(resultSet.getBoolean(columnIndex++));

        if (remarks != null) {

          setBeanValue(object, _DataObjectProperty.Remarks, remarks);
        }

        return object;
      } catch (Exception e) {
        throw new SQLException(e.getMessage());
      }
    }
  }
}
